#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File    : yaml_obj.py
# @Time    : 2021/10/4 16:59
# @Author  : Karl·Marx
import yaml


class YamlObject:
    titles = []

    @staticmethod
    def yaml_load(file):
        with open(file, encoding='utf-8') as f:
            dict_ = yaml.load(f, Loader=yaml.FullLoader)
        return dict_

    @staticmethod
    def case(file, n=None):
        cases_list = []
        titles = []
        with open(file, encoding='utf-8') as f:
            cases = yaml.load(f, Loader=yaml.FullLoader)
        if n:
            for i in n:
                case_tuple = tuple(dict(cases[i - 1]).values())
                titles.append(f'{i}.{case_tuple[0]}')
                cases_list.append(case_tuple)
        else:
            i = 0
            for case in cases:
                i += 1
                case_tuple = tuple(dict(case).values())
                titles.append(f'{i}.{case_tuple[0]}')
                cases_list.append(case_tuple)
        YamlObject.titles = titles
        return cases_list

    @staticmethod
    def title():
        return YamlObject.titles
